home *** CD-ROM | disk | FTP | other *** search
- package javax.help;
-
- import com.sun.java.help.impl.LangElement;
- import com.sun.java.help.impl.Parser;
- import com.sun.java.help.impl.ParserEvent;
- import com.sun.java.help.impl.ParserListener;
- import com.sun.java.help.impl.Tag;
- import com.sun.java.help.impl.TagProperties;
- import java.io.IOException;
- import java.io.Reader;
- import java.util.Hashtable;
- import java.util.Locale;
- import java.util.Stack;
- import javax.swing.tree.DefaultMutableTreeNode;
-
- class TOCView$TOCParser implements ParserListener {
- private HelpSet currentParseHS;
- private Stack nodeStack;
- private Stack itemStack;
- private boolean startedtoc;
- private Stack tagStack;
- private Locale defaultLocale;
- private Locale lastLocale;
- private TreeItemFactory factory;
-
- TOCView$TOCParser(TreeItemFactory var1) {
- this.factory = var1;
- }
-
- synchronized DefaultMutableTreeNode parse(Reader var1, HelpSet var2, Locale var3) throws IOException {
- this.nodeStack = new Stack();
- this.tagStack = new Stack();
- this.itemStack = new Stack();
- if (var3 == null) {
- this.defaultLocale = Locale.getDefault();
- } else {
- this.defaultLocale = var3;
- }
-
- this.lastLocale = this.defaultLocale;
- DefaultMutableTreeNode var4 = new DefaultMutableTreeNode();
- this.nodeStack.push(var4);
- this.currentParseHS = var2;
- Parser var5 = new Parser(var1);
- var5.addParserListener(this);
- var5.parse();
- return var4;
- }
-
- public void tagFound(ParserEvent var1) {
- Locale var2 = null;
- Tag var3 = var1.getTag();
- TOCView.access$000("TagFound: " + var3.name);
- TagProperties var4 = var3.atts;
- if (var4 != null) {
- String var5 = var4.getProperty("xml:lang");
- var2 = HelpUtilities.localeFromLang(var5);
- }
-
- if (var2 == null) {
- var2 = this.lastLocale;
- }
-
- if (var3.name.equals("tocitem")) {
- if (!this.startedtoc) {
- this.factory.reportMessage(HelpUtilities.getText("toc.invalidTOCFormat"), false);
- }
-
- if (var3.isEnd && !var3.isEmpty) {
- this.nodeStack.pop();
- this.itemStack.pop();
- this.removeTag(var3);
- return;
- }
-
- TOCItem var10;
- try {
- Hashtable var6 = null;
- if (var4 != null) {
- var6 = var4.getHashtable();
- }
-
- var10 = (TOCItem)this.factory.createItem("tocitem", var6, this.currentParseHS, var2);
- } catch (Exception var9) {
- if (TOCView.access$100()) {
- String var7 = null;
- Object var8 = null;
- if (var4 != null) {
- var7 = var4.getProperty("target");
- String var14 = var4.getProperty("image");
- }
-
- System.err.println("Failure in IndexItem Creation; ");
- System.err.println(" id: " + var7);
- System.err.println(" hs: " + this.currentParseHS);
- }
-
- var10 = (TOCItem)this.factory.createItem();
- }
-
- DefaultMutableTreeNode var12 = new DefaultMutableTreeNode(var10);
- DefaultMutableTreeNode var13 = (DefaultMutableTreeNode)this.nodeStack.peek();
- var13.add(var12);
- if (!var3.isEmpty) {
- this.itemStack.push(var10);
- this.nodeStack.push(var12);
- this.addTag(var3, var2);
- }
- } else if (var3.name.equals("toc")) {
- TOCView.access$000("attr: " + var4);
- if (!var3.isEnd) {
- if (var4 != null) {
- String var11 = var4.getProperty("version");
- if (var11 != null && var11.compareTo("1.0") != 0) {
- this.factory.reportMessage(HelpUtilities.getText("toc.unknownVersion", var11), false);
- }
- }
-
- if (this.startedtoc) {
- this.factory.reportMessage(HelpUtilities.getText("toc.invalidTOCFormat"), false);
- }
-
- this.startedtoc = true;
- this.addTag(var3, var2);
- } else {
- if (this.startedtoc) {
- this.startedtoc = false;
- }
-
- this.removeTag(var3);
- }
-
- return;
- }
-
- }
-
- public void piFound(ParserEvent var1) {
- }
-
- public void doctypeFound(ParserEvent var1) {
- }
-
- public void textFound(ParserEvent var1) {
- TOCView.access$000("TextFound: " + var1.getText().trim());
- if (!this.tagStack.empty()) {
- LangElement var2 = (LangElement)this.tagStack.peek();
- Tag var3 = var2.getTag();
- if (var3.name.equals("tocitem")) {
- TOCItem var4 = (TOCItem)this.itemStack.peek();
- String var5 = var4.getName();
- if (var5 == null) {
- var4.setName(var1.getText().trim());
- } else {
- var4.setName(var5.concat(var1.getText()).trim());
- }
- }
-
- }
- }
-
- public void commentFound(ParserEvent var1) {
- }
-
- public void errorFound(ParserEvent var1) {
- this.factory.reportMessage(var1.getText(), false);
- }
-
- protected void addTag(Tag var1, Locale var2) {
- LangElement var3 = new LangElement(var1, var2);
- this.tagStack.push(var3);
- if (this.lastLocale == null) {
- this.lastLocale = var2;
- } else if (var2 == null) {
- this.lastLocale = var2;
- } else {
- if (!this.lastLocale.equals(var2)) {
- this.lastLocale = var2;
- }
-
- }
- }
-
- protected void removeTag(Tag var1) {
- String var3 = var1.name;
- Locale var4 = null;
-
- while(!this.tagStack.empty()) {
- LangElement var2 = (LangElement)this.tagStack.pop();
- if (var2.getTag().name.equals(var3)) {
- if (this.tagStack.empty()) {
- var4 = this.defaultLocale;
- } else {
- var2 = (LangElement)this.tagStack.peek();
- var4 = var2.getLocale();
- }
- break;
- }
- }
-
- if (this.lastLocale == null) {
- this.lastLocale = var4;
- } else if (var4 == null) {
- this.lastLocale = var4;
- } else {
- if (!this.lastLocale.equals(var4)) {
- this.lastLocale = var4;
- }
-
- }
- }
- }
-